#pragma once 

#include<iostream>
#include<pthread.h>
#include<string>
#include<ctime>
#include<vector>
#include<unistd.h>

using namespace std;

typedef void (*callback_t)();
static int num = 1;

class Thread
{
public:
    static void* Routine(void* args)
    {
        Thread* t = static_cast<Thread*>(args);
        t->Entery();
        return nullptr;
    }

public:
    Thread(callback_t cb)
        :_tid(0)
        ,_name("")
        ,_start_timestamp(0)
        ,_isrunning(false)
        ,_cb(cb)
    {}

    void run()
    {
        _name = "thread-" + to_string(num++);
        _start_timestamp = time(nullptr);
        _isrunning = true;
        pthread_create(&_tid,nullptr,Routine,this);
    }

    void join()
    {
        pthread_join(_tid,nullptr);
        _isrunning = false;
    }

    ~Thread()
    {}

    string Name()
    {
        return _name;
    }

    uint64_t StartTimeStamp()
    {
        return _start_timestamp;
    }

    bool IsRunning()
    {
        return _isrunning;
    }

    void Entery()
    {
        _cb();
    }
private:
    pthread_t _tid;
    string _name;
    uint64_t _start_timestamp;
    bool _isrunning;

    callback_t _cb;
};